package com.ha8.netease.views.components
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.core.IInvalidating;
	import mx.core.mx_internal;
	import mx.events.FlexMouseEvent;
	
	import spark.components.VScrollBar;
	import spark.core.IViewport;
	import spark.core.NavigationUnit;
	import spark.utils.MouseEventUtil;
	
	use namespace mx_internal;
	
	/**
	 * 
	 * 重写VScrollbar  
	 * 
	 * 修改滚动的速度
	 * 
	 * @author rogo
	 */	
	public class Ha8VScrollBar extends VScrollBar
	{
		public function Ha8VScrollBar()
		{
			super();
		}
		
		override mx_internal function mouseWheelHandler(event:MouseEvent):void
		{
			const vp:IViewport = viewport;
			if (event.isDefaultPrevented() || !vp || !vp.visible || !visible)
				return;
			
			// Dispatch the "mouseWheelChanging" event. If preventDefault() is called
			// on this event, the event will be cancelled.  Otherwise if  the delta
			// is modified the new value will be used.
			var changingEvent:FlexMouseEvent = MouseEventUtil.createMouseWheelChangingEvent(event);
			if (!dispatchEvent(changingEvent))
			{
				event.preventDefault();
				return;
			}
			
			const delta:int = changingEvent.delta;
			
			var nSteps:uint = Math.abs(delta);
			var navigationUnit:uint;
			var scrollPositionChanged:Boolean;
			
			// Scroll delta "steps".          
			navigationUnit = (delta < 0) ? NavigationUnit.DOWN : NavigationUnit.UP;
			for (var vStep:int = 0; vStep < nSteps; vStep++)
			{
				var vspDelta:Number = vp.getVerticalScrollPositionDelta(navigationUnit);
				if (!isNaN(vspDelta))
				{
					
					vp.verticalScrollPosition += (delta < 0) ? 5 : -5;
					scrollPositionChanged = true;
					if (vp is IInvalidating)
						IInvalidating(vp).validateNow();
				}
			}
			
			if (scrollPositionChanged)
				dispatchEvent(new Event(Event.CHANGE));
			
			event.preventDefault();
		}
		
	}
}